package Year22_Month03.day08;

import java.util.Scanner;

public class Main3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int m = sc.nextInt();
            int tmp = m;
            int n = sc.nextInt();
            StringBuilder s = new StringBuilder();//用来接收我们转化后的进制数字
            String arrString = "0123456789ABCDEF";
            boolean flag = false;//用来检测是否是正数
            if(m < 0){
                m = -m;
                flag = true;
            }
            while(m != 0){
                s.append(arrString.charAt(m%n));
                m /= n;
            }
            if(flag){
                s.append("-");
            }
            if(tmp == 0){
                System.out.println(0);
            }else {
                System.out.println(s.reverse());
            }
        }
    }
}
